<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
$gametype = intval(getvar("gametype"));
$gTypeQ = chkGametype($gametype);
switch ($gTypeQ)
{
    case 0 :
        $ui = new UI();
        $gtype = 3;
        break;
    default :
        $gtype = 3;
        include_once( "class_3d/CheckMode_3d.php" );
        $chk = new CheckMode_3d($curruser['acl'], 1, $gametype);
        $chk->checkShow3dPage();
        unset($chk);
        $ui = new UI_3D();
        $ui->header();
        break;
}
include( "class/function_3d.php" );
include( "class_3d/Amounts_float_3d.php" );
$ui = new UI_3D(true);
$tpl = new Template2();
$conf = new Config();
$page = getvar("page");
$page = $page == "" ? 1 : intval($page);
$totalPage = 15;
$memID = getvar("mem");
if ($memID == "")
{
    $ui->showErrorPage("会员资料不足");
}
else
{
    $memID = intval($memID);
}
$cate = getvar("cate");
$cate = $cate == "" ? 0 - 1 : intval($cate);
$error = "";
$msg = intval(getvar("msg"));
if ($msg == 1)
{
    $error = "<strong style=\"color:red\">储值成功！</strong>";
}
else if ($msg == 2)
{
    $error = "<strong style=\"color:red\">结清成功！</strong>";
}
else if ($msg == 3)
{
    $error = "<strong style=\"color:red\">结清失败！</strong>";
}
else if ($msg == 4)
{
    $error = "<strong style=\"color:red\">已结清！</strong>";
}
if ($curruser['acl'] < 255)
{
    $users = getuserlist($curruser['id'], 1);
    if ($users == "")
    {
        diemsg("不是你的会员！");
    }
    $userArrTemp = explode(",", $users);
    if (!in_array($memID, $userArrTemp))
    {
        diemsg("不是你的会员！");
    }
}
$Amounts_float_3d = new Amounts_float_3d();
$memInfo = get_user($memID);
if (intval(getvar("clcAmtFloat")))
{
    $nowAmount = $Amounts_float_3d->getAmountFloat($memID, $gtype);
    if ($nowAmount != 0)
    {
        $aclnameStr = $curruser['acl'] < 255 ? $aclname[$curruser['acl']] : "公司";
        if ($Amounts_float_3d->clrAmountFloat($memID, $curruser['id'], $aclnameStr, $nowAmount * ( 0 - 1 )))
        {
            header("LOCATION:op.php?op=agent&fp=amounts_float&gametype={$gametype}&mem={$memID}&msg=2&cate={$cate}");
        }
        else
        {
            header("LOCATION:op.php?op=agent&fp=amounts_float&gametype={$gametype}&mem={$memID}&msg=3&cate={$cate}");
        }
        exit();
    }
    else
    {
        header("LOCATION:op.php?op=agent&fp=amounts_float&gametype={$gametype}&mem={$memID}&msg=4&cate={$cate}");
        exit();
    }
}
else if (ispost())
{
    $amount = intval(getvar("amount"));
    $nowAmount = $Amounts_float_3d->getAmountFloat($memID, $gtype);
    if ($amount != 0 && $nowAmount <= 0)
    {
        if (0 < $nowAmount + $amount)
        {
            $error = "<strong style=\"color:red\">储值失败: 最大储值额为" . ( $nowAmount * ( 0 - 1 ) ) . "</strong>";
        }
        else
        {
            $Amounts_float_3d->insertData($memID, $curruser['id'], $curruser['account'], $gtype, $amount);
            header("LOCATION:op.php?op=agent&fp=amounts_float&gametype={$gametype}&mem={$memID}&msg=1&cate={$cate}");
            exit();
        }
    }
}
$rs = $Amounts_float_3d->dataListRS($memID, $gtype, $cate, $page, $totalPage);
$list = "";
if ($rs->eof)
{
    $list = "<tr><td  colspan=\"6\" align=\"center\" class=\"td2\">无任何资料</td></tr>";
}
$littleAmountTotal = 0;
while (!$rs->eof)
{
    $list .= "<tr class=\"td2\" align=\"center\">";
    $list .= "<td>" . $rs->f['paperopen'] . "</td>";
    $list .= "<td align=\"right\">" . say_numbercolor($rs->f['amount'], 0) . "</td>";
    $list .= "<td>" . $Amounts_float_3d->cateArr[$rs->f['cate']] . "</td>";
    $list .= "<td>" . $rs->f['prev_account'] . "</td>";
    $list .= "<td>" . $rs->f['uptime'] . "</td>";
    $list .= "</tr>";
    $littleAmountTotal += $rs->f['amount'];
    $rs->next();
}
$maxAmountTotal = $Amounts_float_3d->getAmountFloat($memID, $gtype);
if (0 < $maxAmountTotal)
{
    $maxAmount = 0;
}
else
{
    $maxAmount = $maxAmountTotal * ( 0 - 1 );
}
$sleCateOption = "";
foreach ($Amounts_float_3d->cateArr as $key => $val)
{
    if ($cate == $key)
    {
        $sleCateOption .= "<option value=\"{$key}\" selected=\"selected\">{$val}</option>";
    }
    else
    {
        $sleCateOption .= "<option value=\"{$key}\">{$val}</option>";
    }
}
$trLittleCount = "";
if (1 < $rs->totalpages)
{
    $trLittleCount = "<tr class=\"td1\"  align=\"right\"><th>小计</th><td>" . say_numbercolor($littleAmountTotal, 0) . "</td><td colspan=\"3\">&nbsp;</td></tr>";
}
$tpl->load("main", "amounts_float.htm");
$tpl->set(array("mem" => $memID, "memName" => $memInfo['name'], "memAccount" => $memInfo['account'], "gtypeStr" => $Amounts_float_3d->gtypeStrArr[$gtype], "maxAmount" => $maxAmount, "maxAmountTotal" => say_numbercolor($Amounts_float_3d->getAmountFloat($memID, $gtype, $cate), 0), "tbdList" => $list, "pageLink" => $rs->pageLink(), "action" => "op.php?op=agent&fp=amounts_float&gametype={$gametype}&mem={$memID}&cate={$cate}", "error" => $error, "reloadUrl" => "op.php?op=agent&fp=amounts_float&gametype={$gametype}&mem={$memID}&cate={$cate}", "chgUrl" => "op.php?op=agent&fp=amounts_float&gametype={$gametype}&mem={$memID}&cate=", "sleCateOption" => $sleCateOption, "trLittleCount" => $trLittleCount, "gametype" => $gametype));
$tpl->show("main");
$ui->footer();
?>